package com.yinhd.study.designPatterns.chainOfResponsibility.loggers;

/**
 * @program: study
 * @description:
 * @Author: yinhd
 * @create: 2022-01-25 10:25
 **/
public abstract class AbstractLogger {
    public static int INFO = 1;
    public static int DEBUG = 2;
    public static int ERROR = 3;

    protected int level;
    protected AbstractLogger nextLogger;

    public void setNextLogger(AbstractLogger abstractLogger) {
        this.nextLogger = abstractLogger;
    }

    public void printlnMessage(int level, String message) {  //执行规则
        if (this.level <= level) {
            this.write(message);
        } else {
            if (nextLogger != null) {
                nextLogger.printlnMessage(level, message);
            }
        }
    }

    abstract protected void write(String message);
}
